﻿using Infrastructure;
using OpenAuth.Hospital.Model;
using System;
using System.Collections.Generic;
using log4net;
using System.Linq;
using OpenAuth.App;

namespace OpenAuth.Hospital
{
    public class HospitalApi
    {
        private ILog log = LogManager.GetLogger(typeof(HospitalApi));

        private string winningUrl = "https://bp.winning-health.com.cn:15571/winbx/p";
        private string yydm = "TS40225039-5";

        private string accesskey =
            "3248182A1AADC75361A7AAD7DAE6A2D7F9EDC60A1D9104282505B929FAEA1A9F3B8F82E3CCB064C9315F032FF20F5824731B4CBF44D9202112BCF06408E8FC43";

        private string GetHtml(Dictionary<string, string> dic)
        {
            try
            {
              

                HttpHelper h = new HttpHelper("http://192.168.0.33:8080/");
          
                string result = h.Get(dic, winningUrl);
                log.Info($"[{dic["action"]}]\r\n" +
                         $"Url=>{winningUrl + "?" + string.Join("&", dic.Select(o => o.Key + "=" + o.Value))}\r\n" +
                         $"Result=>{result}");
                return result;
            }
            catch (Exception e)
            {
                log.Info($"Action[{dic["action"]}]   异常:{e.Message}");
                return new ApiResult { success = false, message = "异常:" + e.Message }.ToJson();
            }

        }
        /// <summary>
        /// 查询门诊患者基本信息(卡号)
        /// </summary>
        /// <param name="bxh"></param>
        /// <returns></returns>
        public string GETMZHZBXH(string bxh)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETMZHZBXH");
            dic.Add("bxh", bxh);
            return GetHtml(dic);
        }
        /// <summary>
        /// 查询住院患者基本信息(病历号)（GETZYHZBLH）
        /// </summary>
        /// <param name="blh">病历号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        public string GETZYHZBLH(string blh, string hzxm)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETZYHZBLH");

            dic.Add("blh", blh);
            dic.Add("hzxm", hzxm);
            return GetHtml(dic);
        }
        /// <summary>
        /// 查询住院患者基本信息(卡号)
        /// </summary>
        /// <param name="bxh">卡号</param>
        /// <param name="hzxm">患者姓名</param>
        /// <returns></returns>
        public string GETZYHZBXH(string bxh, string hzxm)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETZYHZBXH");
            dic.Add("hzxm", hzxm);
            dic.Add("bxh", bxh);
            return GetHtml(dic);
        }
        /// <summary>
        /// 查询住院患者就诊记录(PATID)（GETZYJLPAT）
        /// </summary>
        /// <param name="patid"></param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        public string GETZYJLPAT(string patid,string hzxm, string zyzt)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETZYJLPAT");

            dic.Add("hzxm", hzxm);
            dic.Add("patid", patid);
            dic.Add("zyzt", zyzt);//0 全部 1 仅在院
            return GetHtml(dic);
        }

        /// <summary>
        /// 查询门诊患者待缴费处方信息
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ksrq">开始日期</param>
        /// <param name="jsrq">结束日期 </param>
        /// <param name="ybrc">医保入参</param>
        /// <returns></returns>
        public string GETMZSFCF(string hzxm,string patid,string ksrq,string jsrq,string ybrc)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETMZSFCF");

            dic.Add("hzxm", hzxm);
            dic.Add("patid", patid);
            dic.Add("ksrq", ksrq);
            dic.Add("jsrq", jsrq);
            dic.Add("ybrc", ybrc);
            return GetHtml(dic);
        }
        /// <summary>
        /// 查询住院患者预交金汇总信息
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm">患者姓名</param>
        /// <returns></returns>
        public string GETZYYJJHZ(string jzlsh, string hzxm)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETZYYJJHZ");
            dic.Add("hzxm", hzxm);
            dic.Add("jzlsh", jzlsh);
            return GetHtml(dic);
        }
        /// <summary>
        /// 查询住院患者预交金明细信息
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        public string GETZYYJJMX(string jzlsh, string hzxm)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "GETZYYJJMX");
            dic.Add("hzxm", hzxm);
            dic.Add("jzlsh", jzlsh);
            return GetHtml(dic);
        }
        /// <summary>
        /// 住院预交金预充值
        /// </summary>
        /// <param name="jzlsh">住院就诊流水号</param>
        /// <param name="hzxm"></param>
        /// <returns></returns>
        public string PUTZYYJJYS(string jzlsh, string hzxm)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTZYYJJYS");
            dic.Add("hzxm", hzxm);
            dic.Add("jzlsh", jzlsh);
            return GetHtml(dic);
        }
        /// <summary>
        /// 住院预交金充值
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string PUTZYYJJ(PUTZYYJJ_Input input)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTZYYJJ");

            dic.Add("hzxm", input.hzxm ?? "");
            dic.Add("jzlsh", input.jzlsh ?? "");
            dic.Add("yjlsh", input.yjlsh ?? "");
            dic.Add("hisddh", input.hisddh ?? "");
            dic.Add("ptlsh", input.ptlsh ?? "");
            dic.Add("zffs", input.zffs ?? "");
            dic.Add("zfje", input.zfje ?? "");
            dic.Add("zflsh", input.zflsh ?? "");
            dic.Add("zfsj", input.zfsj ?? "");
            dic.Add("lxdh", input.lxdh ?? "");
            dic.Add("lxrxm", input.lxrxm ?? "");
            dic.Add("lxrzjh", input.lxrzjh ?? "");

            return GetHtml(dic);
        }
        /// <summary>
        /// 门诊收费预算
        /// </summary>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ghxh">门诊挂号序号</param>
        /// <param name="cfxhhj">划价序号合集</param>
        /// <param name="isynzh">是否扣院内账户</param>
        /// <param name="iszfjs">是否自费结算</param>
        /// <param name="ybrc">医保交易入参</param>
        /// <returns></returns>
        public string PUTMZYS(string patid, string ghxh, string cfxhhj, string isynzh, string iszfjs, string ybrc)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZYS");


            dic.Add("patid", patid);
            dic.Add("ghxh", ghxh);
            dic.Add("cfxhhj", cfxhhj);
            dic.Add("isynzh", isynzh);
            dic.Add("iszfjs", iszfjs);
            dic.Add("ybrc", ybrc);


            return GetHtml(dic);
        }
        /// <summary>
        /// 门诊收费预算撤销
        /// </summary>
        /// <param name="sjh">收据号</param>
        /// <param name="patid">门诊 patid</param>
        /// <param name="ybrc">医保交易入参 </param>
        /// <returns></returns>
        public string PUTMZYSQX(string sjh, string patid, string ybrc)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZYSQX");


            dic.Add("sjh", sjh);
            dic.Add("patid", patid);
            dic.Add("ybrc", ybrc);


            return GetHtml(dic);
        }
        /// <summary>
        /// 门诊收费结算
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string PUTMZJS(PUTMZJS_Input input)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZJS");


            dic.Add("patid", input.patid ?? "");
            dic.Add("ghxh", input.ghxh ?? "");
            dic.Add("sjh", input.sjh ?? "");
            dic.Add("ptlsh", input.ptlsh ?? "");
            dic.Add("cfxhhj", input.cfxhhj ?? "");
            dic.Add("zje", input.zje ?? "");
            dic.Add("yfje", input.yfje ?? "");
            dic.Add("zffs", input.zffs ?? "");
            dic.Add("zfje", input.zfje ?? "");
            dic.Add("zflsh", input.zflsh ?? "");
            dic.Add("zfsj", input.zfsj ?? "");
            dic.Add("isynzh", input.isynzh ?? "");
            dic.Add("iszfjs", input.iszfjs ?? "");
            dic.Add("ybrc", input.ybrc ?? "");
            string str = "";
            str = GetHtml(dic);
       
            return str;
        }
        /// <summary>
        /// 门诊预交金预充值
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid"></param>
        /// <returns></returns>
        public string PUTMZYJJYS(string hzxm, string patid)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZYJJYS");

            dic.Add("hzxm", hzxm);
            dic.Add("patid", patid);
            return GetHtml(dic);
        }
        /// <summary>
        /// 门诊预交金充值
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid">门诊患者唯一号</param>
        /// <param name="sjh">收据号</param>
        /// <param name="hisddh">HIS 订单号</param>
        /// <param name="ptlsh">平台流水号</param>
        /// <param name="zffs">支付方式</param>
        /// <param name="zfje">支付金额</param>
        /// <param name="zflsh">支付流水号</param>
        /// <param name="zfsj">支付时间</param>
        /// <returns></returns>
        public string PUTMZYJJ(string hzxm, string patid, string sjh, string hisddh, string ptlsh,
       string zffs, string zfje, string zflsh, string zfsj)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZYJJ");

            dic.Add("hzxm", hzxm);
            dic.Add("patid", patid);
            dic.Add("sjh", sjh);
            dic.Add("hisddh", hisddh);
            dic.Add("ptlsh", ptlsh);
            dic.Add("zffs", zffs);
            dic.Add("zfje", zfje);
            dic.Add("zflsh", zflsh);
            dic.Add("zfsj", zfsj);
            return GetHtml(dic);
        }
        /// <summary>
        /// 门诊预交金退费
        /// </summary>
        /// <param name="hzxm"></param>
        /// <param name="patid"></param>
        /// <param name="yjxh">预交金序号</param>
        /// <param name="hisddh">HIS 订单号</param>
        /// <param name="ptlsh">平台流水号</param>
        /// <returns></returns>
        public string PUTMZYJJQX(string hzxm, string patid, string yjxh, string hisddh, string ptlsh)
        {

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("yydm", yydm);
            dic.Add("accesskey", accesskey);
            dic.Add("action", "PUTMZYJJQX");

            dic.Add("hzxm", hzxm);
            dic.Add("patid", patid);
            dic.Add("yjxh", yjxh);
            dic.Add("hisddh", hisddh);
            dic.Add("ptlsh", ptlsh);

            return GetHtml(dic);
        }
    }
}
